from visual_object_3D import *
from types import StringType
'''
	Andrew Oberlin
	Date: March 7, 2012
'''
class ObjectConstants:
	TEXTURE = 0
	OBJECT = 1
	SAND = 2
	GRASS = 3
	ROCK = 4
	CRACKED_SAND = 5
	CRACKED_ROCK = 6
	CRACKED_DIRT = 7
	DIRTY_ROCK = 8
	DIRT = 9
	WATER = 10
	MINERALS = 11
	VESPENE = 12
	COMMAND_CENTER = 13
	INFESTED_COMMAND_CENTER = 14
	ZERGLING = 15
	SCV = 16
	BARRACKS = 17
	MARINE = 18
	
	def __init__(self):
		self.uniqueNum = 0
		
		self.noToTexture = {
			self.SAND : "models/terrain/sand.png",
			self.GRASS : "models/terrain/grass.png",
			self.ROCK : "models/terrain/rock.png",
			self.CRACKED_SAND : "models/terrain/cracked_sand.png",
			self.CRACKED_ROCK : "models/terrain/cracked_rock.png",
			self.CRACKED_DIRT : "models/terrain/cracked_dirt.png",
			self.DIRTY_ROCK : "models/terrain/dirty_rock.png",
			self.DIRT : "models/terrain/dirt.png",
			self.WATER : "models/terrain/water.png",
			self.MINERALS : "models/terrain/minerals.png",
			self.VESPENE : "models/terrain/vespene.png",
			self.COMMAND_CENTER : "models/terran/buildings/command_center.png",
			self.BARRACKS : "models/terran/buildings/barracks.png",
			self.ZERGLING : "models/zerg/characters/zergling/zergling_0.png",
			self.INFESTED_COMMAND_CENTER : "models/zerg/buildings/infested_command_center.png",
			self.SCV : "models/terran/characters/scv.png",
			self.MARINE : "models/zerg/characters/marine/marine_walk_0.png",
		}
		
		self.textureToNo = {
			"models/terrain/sand" : self.SAND,
			"models/terrain/grass" : self.GRASS,
			"models/terrain/rock" : self.ROCK,
			"models/terrain/cracked_sand" : self.CRACKED_SAND,
			"models/terrain/cracked_rock" : self.CRACKED_ROCK,
			"models/terrain/cracked_dirt" : self.CRACKED_DIRT,
			"models/terrain/dirty_rock" : self.DIRTY_ROCK,
			"models/terrain/dirt" : self.DIRT,
			"models/terrain/water" : self.WATER,
			"models/terrain/minerals" : self.MINERALS,
			"models/terrain/vespene" : self.VESPENE,
			"models/terran/buildings/command_center" : self.COMMAND_CENTER,
			"models/terran/buildings/barracks" : self.BARRACKS,
			"models/zerg/characters/zergling/zergling_0" : self.ZERGLING,
			"models/zerg/buildings/infested_command_center" : self.INFESTED_COMMAND_CENTER,
			"models/terran/characters/scv" : self.SCV,
			"models/zerg/characters/marine/marine_walk_0" : self.MARINE,
		}
		
		self.objects = {
			self.MINERALS : "models/terrain/minerals.png",
			self.VESPENE : "models/terrain/vespene.png",
			self.COMMAND_CENTER : "models/terran/buildings/command_center.png",
			self.BARRACKS : "models/terran/buildings/barracks.png",
			self.INFESTED_COMMAND_CENTER : "models/zerg/buildings/infested_command_center.png",
			self.ZERGLING : "models/zerg/characters/zergling/zergling_0.png",
			self.SCV : "models/terran/characters/scv.png",
			self.MARINE : "models/zerg/characters/marine/marine_walk_0.png"
		}
		
		self.enemies = {
			self.ZERGLING : True
		}
		
		self.enemyBuildings = {
			self.INFESTED_COMMAND_CENTER : True
		}
	
	def getNoFromTexture(self, switch, extension=True):
		if (extension):
			extenseLoc = switch.rfind(".")
			if (extenseLoc >= 0):
				switch = switch[:extenseLoc]
		if (self.textureToNo.has_key(switch)):
			return self.textureToNo[switch]
		else:
			return ""

		
	def getTextureFromNo(self, switch, tuple=True, extension=True):
		if (self.noToTexture.has_key(switch)):
			texture = self.noToTexture[switch]
		else:
			texture = ""
			
		name = str(switch) + "_texture"
			
		if (not extension):
			extenseLoc = texture.rfind(".")
			if (extenseLoc >= 0):
				texture = texture[:extenseLoc]
		
		if (not tuple):
			return texture
		else:
			return (texture, name)
			
	def getObjectFromNo(self, switch, parent, dummy, key=None):
		if (key == None):
			self.uniqueNum += 1
			key = 'generic_' + str(self.uniqueNum)
		if (switch == self.MINERALS):
			return VisualObject3D(parent, dummy, key)
		elif (switch == self.VESPENE):
			return Vespene(parent, dummy, key)
		elif (switch == self.COMMAND_CENTER):
			return CommandCenter(parent, dummy, key)
		elif (switch == self.BARRACKS):
			return Barracks(parent, dummy, key)
		elif (switch == self.INFESTED_COMMAND_CENTER):
			return InfestedCommandCenter(parent, dummy, key)
		elif (switch == self.ZERGLING):
			self.uniqueNum += 1
			return AnimatedObject3D(parent, dummy, key)
		elif (switch == self.SCV):
			return SCV(parent, dummy, key)
		elif (switch == self.MARINE):
			return Marine(parent, dummy, key)
		else:
			return None
			
	def getObjectFromTexture(self, switch, parent, dummy, key=None, extension=True):
		if (extension):
			extenseLoc = switch.rfind(".")
			if (extenseLoc >= 0):
				switch = switch[:extenseLoc]
				
		if (self.textureToNo.has_key(switch)):
			return self.getObjectFromNo(self.textureToNo[switch], parent, dummy, key=key)
		else:
			if (switch[len(switch) - 2] == '_'):
				switch = switch[:len(switch) - 2]
				if (self.textureToNo.has_key(switch)):
					return self.getObjectFromNo(self.textureToNo[switch], parent, dummy, key=key)
			return None
			
	def isObject(self, switch, extension=True):		
		if (isinstance(switch, StringType)):
			if (extension):
				extenseLoc = switch.rfind(".")
				if (extenseLoc >= 0):
					switch = switch[:extenseLoc]
				
			if (self.textureToNo.has_key(switch)):
				switch = self.textureToNo[switch]
			else:
				if (switch[len(switch) - 2] == '_'):
					switch = switch[:len(switch) - 2]
					if (self.textureToNo.has_key(switch)):
						switch = self.textureToNo[switch]
					else:
						return False
				else:
					return False
		
		if (self.objects.has_key(switch)):
			return True
		else:
			return False
			
	def isEnemy(self, key):
		return self.enemies.has_key(key)
		
	def isEnemyBuilding(self, key):
		return self.enemyBuildings.has_key(key)
			
			